home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 4.5 KB | 158 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGrObj.h
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWGROBJ_H
- #define FWGROBJ_H
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include <FWStdDef.h>
- #endif
-
- //==============================================================================
- // •• class FW_CGraphicObjectRep
- //==============================================================================
-
- class FW_CGraphicObjectRep
- {
- friend class FW_CGraphicObjectPtr;
-
- //------------------------------------------------------------------------------
- // • Constructors/Destructors
- //
- friend class FW_CGraphicObjectPtr;
-
- protected:
- FW_CGraphicObjectRep();
- virtual ~FW_CGraphicObjectRep();
-
- //------------------------------------------------------------------------------
- // • New API
- //
- public:
- unsigned long GetSeed() const
- {return fSeed;}
-
- unsigned long GetRefCount() const
- {return fRefCount;}
-
- virtual void Flatten(FW_CWritableStream& stream) = 0;
- virtual void Unflatten(FW_CReadableStream& stream) = 0;
-
- protected:
- void Changed();
-
- void IncrementRefCount()
- {fRefCount++;}
- unsigned long Release()
- {return --fRefCount;}
-
- //------------------------------------------------------------------------------
- // • Data Members
- //
- private:
- unsigned long fSeed;
- unsigned long fRefCount;
- };
-
- //========================================================================================
- // •• CLASS FW_CGraphicObjectPtr
- //========================================================================================
-
- class FW_CGraphicObjectPtr
- {
- public:
- FW_CGraphicObjectPtr();
- // Creates a "NULL" pointer.
-
- FW_CGraphicObjectPtr(const FW_CGraphicObjectPtr& other);
- // FW_SPlatformPoint this pointer to the same rep as the other pointer points to.
-
- FW_CGraphicObjectPtr(FW_CGraphicObjectRep* rep);
- // Creates a pointer pointing at rep.
-
- ~FW_CGraphicObjectPtr();
- // Destroy the pointer.
- // Decrements the count in the rep, and deletes the rep if count is zero.
-
- /*
- FW_CGraphicObjectPtr& operator=(const FW_CGraphicObjectPtr& other);
- // Assignment, point this pointer to the same rep as the other pointer points to.
-
- FW_CGraphicObjectPtr& operator=(FW_CGraphicObjectRep* rep);
- // Assignment, point this ponter to rep.
-
- FW_CGraphicObjectRep* operator->() const;
- // Provide access to members of rep.
-
- FW_CGraphicObjectRep& operator*() const;
- // Provide access to rep.
- // This operator should be used only if operator->() is not sufficient.
- */
-
- FW_Boolean operator==(const FW_CGraphicObjectPtr& other) const;
- // Points to the same representation object?
-
- FW_Boolean operator!=(const FW_CGraphicObjectPtr& other) const;
- // Points to a different representation object?
-
- operator const void*() const;
- // Use to test if this is a "NULL" pointer.
-
- protected:
- void UpCount();
- // Implementation method, increment the reference count in rep.
-
- void DownCount();
- // Implementation method, decrement the reference count in rep.
- // Deletes rep if reference count is zero.
-
- FW_CGraphicObjectRep* GetRep() const
- {return fRep;}
- void SetRep(FW_CGraphicObjectRep* rep);
-
- private:
- FW_CGraphicObjectRep *fRep;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicObjectPtr::operator==
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CGraphicObjectPtr::operator==(const FW_CGraphicObjectPtr& other) const
- {
- return (fRep == other.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicObjectPtr::operator!=
- //----------------------------------------------------------------------------------------
-
- inline FW_Boolean FW_CGraphicObjectPtr::operator!=(const FW_CGraphicObjectPtr& other) const
- {
- return !operator==(other);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicObjectPtr::operator const void*
- //----------------------------------------------------------------------------------------
-
- inline FW_CGraphicObjectPtr::operator const void*() const
- {
- return (const void*) fRep;
- }
-
- #endif